//
//  MXMessageDetailVC.m
//  HNBaseProject
//
//  Created by TR on 2024/6/26.
//

#import "MXMessageDetailVC.h"
#import "MxPublicNav.h"
@interface MXMessageDetailVC ()<MxNavigationViewDelegate>

@property (nonatomic, strong) MxPublicNav *nav;
@property(nonatomic,strong)UIView         *bgView;
@property(nonatomic,strong)UILabel              *titleLab;
@property(nonatomic,strong)UILabel              *timeLab;
@property(nonatomic,strong)UILabel              *contentLab;

@end

@implementation MXMessageDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    [self getdetail];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self dc_navBarHidden:YES];
}

- (void)setUI{
    self.nav = [[MxPublicNav alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kNavBarHeight)];
    self.nav.titleLab.text = @"消息详情";
    self.nav.delegate = self;
    [self.view addSubview:self.nav];
    
    self.bgView = [[UIView alloc]init];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.bgView];
    
    self.titleLab = [[UILabel alloc]init];
    self.titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
    self.titleLab.font = PFRFontMedium(19);
    self.titleLab.text = self.model.appNotice.noticeTitle;
    [self.bgView addSubview:self.titleLab];
    
    self.timeLab = [[UILabel alloc]init];
    self.timeLab.textColor = [UIColor colorWithHexString:@"#999999"];
    self.timeLab.font = [UIFont systemFontOfSize:11];
    self.timeLab.text = [NSString stringWithFormat:@"发布于：%@",self.model.appNotice.createTime];
    [self.bgView addSubview:self.timeLab];
    
    self.contentLab = [[UILabel alloc]init];
    self.contentLab.textColor = [UIColor colorWithHexString:@"#000000"];
    self.contentLab.font = [UIFont systemFontOfSize:14];
    self.contentLab.text = self.model.appNotice.noticeContent;
    self.contentLab.numberOfLines = 0;
    [self.bgView addSubview:self.contentLab];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(18+kNavBarHeight);
        make.left.offset(21);
        make.right.offset(-21);
        make.bottom.offset(0);
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_top).offset(34);
        make.left.equalTo(self.bgView.mas_left).offset(19);
        make.right.equalTo(self.bgView.mas_right).offset(-19);
    }];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLab.mas_bottom).offset(18);
        make.left.equalTo(self.bgView.mas_left).offset(19);
        make.right.equalTo(self.bgView.mas_right).offset(-19);
    }];
    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLab.mas_bottom).offset(23);
        make.left.equalTo(self.bgView.mas_left).offset(19);
        make.right.equalTo(self.bgView.mas_right).offset(-19);
    }];
}

#pragma mark----返回------
-(void)leftTap {
    [self.navigationController popViewControllerAnimated:YES];
}
//详情
- (void)getdetail {

    MJWeakSelf
    NSDictionary *param = @{@"noticeDetailId":SAFEPARAMETER(self.model.appNotice.ID)};
    [self.view makeToastActivity];
    [[DCHttpClient shareClient] requestWithPath:@"api/app/notice/view" params:param httpMethod:DCHttpRequestGet sucess:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        NSDictionary * dict = [responseObject mj_JSONObject];
        [weakSelf.view hideToastActivity];
        if (dict[DC_ResultCode_Key] && [dict[DC_ResultCode_Key] integerValue] == DC_Result_Success) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"redHide" object:self.model.appNotice.ID];
        } else {
            [weakSelf.view xjmakeToast:dict[DC_ResultMsg_Key]];
        }
        
    } failture:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        [weakSelf.view hideToastActivity];
    }];
}
@end
